#include "stack.h"

int stack_init(struct stack *p_stack , int *p_buf, int s32Size)
{
    p_stack->s32Top = 0;
    p_stack->s32Size = s32Size;
    p_stack->p_buf = p_buf;
    return 0;
}


int stack_push(struct stack *p_stack, int val)
{
    if(p_stack->s32Top != p_stack->s32Size) {
        p_stack->p_buf[p_stack->s32Top++] = val;
        return 0;
    }

    return -1;
}


int stack_pop(struct stack *p_stack, int *p_val)
{
    if(p_stack->s32Top != 0) {
        *p_val = p_stack->p_buf[--p_stack->s32Top];
        return 0;
    }

    return -1;
}

int stack_deinit(struct stack *p_stack)
{
    return 0;
}
